package com.bilicute.libman.service.impl;

import com.bilicute.libman.mapper.RecordMapper;
import com.bilicute.libman.pojo.Book;
import com.bilicute.libman.pojo.Record;
import com.bilicute.libman.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @所属包名: com.bilicute.libman.service.impl
 * @类名: RecordServiceImpl
 * @作者: i囡漫笔
 * @描述: 记录借阅图书记录
 * @创建时间: 2024-06-23 08:49
 */

@Service
public class RecordServiceImpl implements RecordService {
    private RecordMapper recordMapper;
    @Autowired
    public void setRecordMapper(RecordMapper recordMapper) {
        this.recordMapper = recordMapper;
    }

    @Override
    public String newRecord(Book bookById, Integer loggedInUserId) {
        Map<String,Object> map = new HashMap<>();
        map.put("record_id", UUID.randomUUID().toString());
        map.put("record_book_name",bookById.getBook_name());
        map.put("record_book_isbn",bookById.getBook_isbn());
        map.put("record_borrower",loggedInUserId);
        recordMapper.newRecord(map);
        return String.valueOf(map.get("record_id"));
    }

    @Override
    public void returnBook(String record_id) {
        recordMapper.returnBook(record_id);
        System.out.println(record_id);
    }
}
